package com.yznu.jaee.reflect;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

class Service{
	public <T> void test1(T t) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
		 Class clazz = t.getClass();
		 Field[] fields=clazz.getDeclaredFields();   //反射
		 Method[] methods = clazz.getDeclaredMethods();
		 
		 for (int i = 0; i < fields.length; i++) {
             //获取字段
             Field field = fields[i];
             //设置私有属性可访问
             field.setAccessible(true);
             //获取值
             Object value = field.get(t);  //反射
             System.out.println(value);
		 }
		 for (int i = 0; i < methods.length; i++) {
             //获取字段
			 Method method = methods[i];
			 //设置私有属性可访问
			 method.setAccessible(true);
             //获取值
             if(method.getName().equals("getName"))
            	 method.invoke(t);
             if(method.getName().equals("setName"))
            	 method.invoke(t,"123");
		 }
	}
}